#include <cstdio>
#include <iostream>

using namespace std;

int g[1000][1000];
int color[1000];
bool used[1000];
int n;

bool dfs(int v, int c)
{
	used[v] = true;
	color[v] = c;
	for (int u = 0; u < n; u++)
		if (g[v][u] == 1)
		{	
			if (used[u] && (color[u] + color[v]) != 3) return false;
			if (!used[u])
				if (!dfs(u, 3 - c))
					return false;
		}
	return true;
}

int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cin >> n;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			cin >> g[i][j];
	for (int  i = 0; i < n; i++)
		used[i] = false;
	bool f = true;
	for (int u = 0; u < n; u++)
		if (!used[u])
			if (!dfs(u, 1))
				f = false;
	if (f) cout << "YES";
	else cout << "NO";
}


